const adminUser = require("../entities/adminUser");
const { assignProporties, getButton, getTextBox, getRowSpanText, getSelect2 } = require("../Common");

//systemManage/用户编辑 300-399
const dataActionTypes = {
    //获取实体数据
    getEntityData: 300,
    //保存实体数据
    saveEntityData: 301
}

const { name, primaryKey } = adminUser;
const entity = { name, primaryKey };

const menuItem = { Name: 'MenuItem', primaryKey: "Id" }

module.exports = {
    name: "adminUserEdit",
    type: "View",
    eventActions: getEventActions(),
    properties: assignProporties({ name: "adminUserEdit" }, [getEditView()])
}

function getEditView() {
    return {
        name: "adminUserEdit2",
        type: "RowsColsView",
        entity: entity,
        isForm: true,
        loadActionName: "getEntityData",
        isClear: true,
        className: 'divView3',
        saveEntityDataActionType: dataActionTypes.saveEntityData,
        getEntityDataActionType: dataActionTypes.getEntityData,
        properties: assignProporties(adminUser, getProperties())
    }
}

function getButtonProperties() {
    return [{
        name: "leftSpace1",
        type: "WhiteSpace",
        className: "ant-col ant-col-8 ant-form-item-label"
    },
    { ...getButton("saveEntityData", "保存", "primary"), icon: 'save', eventActionName: "saveEntityData", style: { width: 84 } },
    { ...getButton("backToList", "返回", ""), icon: 'left', eventActionName: "backToList", style: { marginLeft: 10 } }]
}

function getProperties() {
    return [
        getTextBox2("LoginName", "登录名", 1, 1, "", "请输入登录名", 50, false),
        getTextBox2("UserName", "用户名", 2, 1, "", "请输入用户名", 50, false),
        getEditSelect2("EmployeeId", "所属员工", adminUser.employeesDataSource, 3, 1, true, '请选择员工'),
        { ...getTextBox2("LoginPassword", "登录密码", 4, 1, "", "请输入登录密码", 50, true), isJudgeNullable: false, controlType: "password" },
        { ...getTextBox2("LoginAgainPassword", "密码确认", 5, 1, "", "请输入密码确认", 50, true), isJudgeNullable: false, controlType: "password" },
        getCheckBoxList2("RightGroupIds", "权限组", adminUser.rightGroupsDataSources, 6, 1, true),
        getComplexView(),
        getButtonView()
    ]
}

function getEditSelect2(name, label, serviceDataource, x, y, isNullable, placeHolder, defaultValue) {
    return {
        ...getSelect2(name, label, serviceDataource, x, y, defaultValue),
        isFormItem: true,
        placeHolder,
        colSpan: 24,
        labelCol: 8,
        wrapperCol: 8,
        operateLogic: "=",
        isEdit: true,
        isNullable
    }
}


function getTextBox2(name, label, x, y, contorlType, placeHolder, maxLength, isNullable, isVisible, validateNames, validateTipMessage) {
    return {
        ...getTextBox(name, label, contorlType, x, y, placeHolder, maxLength || 50),
        validateNames, validateTipMessage,
        isFormItem: true,
        colSpan: 24,
        labelCol: 8,
        wrapperCol: 8,
        isNullable,
        isVisible,
        isEdit: true
    }
}


function getCheckBoxList2(name, label, serviceDataSource, x, y, isNullable) {
    return {
        name, label, serviceDataSource, x, y, isNullable,
        isFormItem: true,
        colSpan: 24,
        labelCol: 8,
        wrapperCol: 8,
        isEdit: true,
        isString: true,
        type: 'CheckBoxGroup',
        valueName: 'RightGroupId',
        textName: 'Name'
    }
}


function getButtonView() {
    return {
        name: "buttonView",
        type: "View",
        className: "divCenterButton",
        isDiv: true,
        isFormItem: true,
        colSpan: 24,
        x: 8,
        y: 1,
        properties: assignProporties({ name: "adminUserEdit" }, getButtonProperties())
    }
}

function getComplexView() {
    return {
        name: "MenuRights",
        type: "ComplexDataGrid",
        title: '菜单权限',
        isEdit: true,
        isNullable: true,
        isEdit: true,
        isNullable: true,
        isAdd: false,
        x: 7,
        y: 1,
        colSpan: 24,
        properties: assignProporties(menuItem, getComplexProperties())
    }
}

function getComplexProperties() {
    return [
        getRowSpanText("NavMenuName", "导航菜单", 6),
        getRowSpanText("Name", "页面菜单", 6),
        getRowSpanText("AccessRightName", "菜单访问权限", 4),
        getRowSpanText("DataRightName", "数据权限", 4),
        getRowSpanText("OperationRightName", "操作权限", 4),
    ]
}

function getEventActions() {
    return [{
        name: "backToList",
        type: "page/toPage",
        propertyNames: [entity.primaryKey],
        pageUrl: '/adminUserList.html?selectedRowKey=#{' + entity.primaryKey + '}'
    },
    {
        name: "saveEntityData",
        type: "entityEdit/saveEntityData",
        editView: "adminUserEdit2",
        expandSetEntityData: "expandSetEntityData"
    },
    {
        name: "getEntityData",
        type: "entityEdit/getEntityData",
        editView: "adminUserEdit2"
    }]
}